/*
 * Powered By [Frank-Liz-Lee]
 * Copyright(C) 2012-2016 Liz Company
 * All rights reserved.
 */

package com.linln.modules.system.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linln.common.enums.StatusEnum;
import com.linln.modules.system.mapper.SysLogMapper;
import com.linln.modules.system.domain.SysLog;
import java.util.List;

import com.linln.modules.system.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

@Transactional(rollbackFor = Exception.class)
@Service
public class SysLogServiceImpl  extends GenericService<SysLog, Long>  implements SysLogService {

    private SysLogMapper sysLogMapper;

    @Autowired
    public void setSysLogMapper(SysLogMapper sysLogMapper) {
        this.sysLogMapper = sysLogMapper;
    }

    /**
     * 通过主键查询实体对象
     * @param primaryKey
     * @return
     * @
     */
    public SysLog getByPK(Long primaryKey)  {
        return sysLogMapper.getByPK(primaryKey);
    }

    /**
     * 查询所有记录
     * @return
     * @
     */
    public List<SysLog> list()  {
        return sysLogMapper.list();
    }

    /**
     * 根据查询条件查询所有记录
     * @return
     * @
     */
    public List<SysLog> listByProperty(SysLog sysLog) {
        return sysLogMapper.listByProperty(sysLog);
    }


    /**
     * 根据主键删除记录
     * @param primaryKey
     * @return
     * @
     */
    public int deleteByPK(Long primaryKey)  {
        return sysLogMapper.deleteByPK(primaryKey);
    }

    /**
     * 根据多个主键删除记录
     * @param primaryKeys
     * @
     */
    public int deleteByPKeys(List<Long> primaryKeys)  {
        return sysLogMapper.deleteByPKeys(primaryKeys);
    }

    /**
     * 根据传入参数删除记录
     * @param sysLog
     * @return
     * @
     */
    public int deleteByProperty(SysLog sysLog)  {
        return sysLogMapper.deleteByProperty(sysLog);
    }

    /**
     * 保存记录
     * @param sysLog
     * @return
     * @
     */
    public int save(SysLog sysLog)  {
        return sysLogMapper.save(sysLog);
    }

    /**
     * 更新记录
     * @param sysLog
     * @return
     * @
     */
    public int update(SysLog sysLog) {
        return sysLogMapper.update(sysLog);
    }

    /**
     * 根据条件查询记录条数
     * @param sysLog
     * @return
     * @
     */
    public int findByCount(SysLog sysLog)  {
        return sysLogMapper.findByCount(sysLog);
    }

    /**
     * 根据查询条件查询分页记录
     * @return
     */
    public PageInfo<SysLog> findByPage(Integer pageNum, Integer pageSize, SysLog sysLog) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysLog> sysLogList = sysLogMapper.listByProperty(sysLog);
        if(null == sysLogList || sysLogList.size() == 0){
            return new Page<SysLog>().toPageInfo();
        }
        Page<SysLog> page =  (Page<SysLog>)sysLogList;
            return page.toPageInfo();
    }

    public boolean updateStatus(StatusEnum statusEnum, List<Long> ids) {
        if(null == statusEnum || CollectionUtils.isEmpty(ids)){
            return false;
        }
        int result =  sysLogMapper.updateStatus(statusEnum.getCode(),ids);
        return result > 0;
    }
}
